/**
 * 联系表单消息模型
 * @module models/Message
 */

const { DataTypes } = require('sequelize');
const { sequelize } = require('../config/database');

/**
 * 消息模型定义
 * @typedef {Object} Message
 * @property {string} name - 姓名
 * @property {string} email - 邮箱
 * @property {string} subject - 主题
 * @property {string} content - 内容
 * @property {boolean} read - 是否已读
 */
const Message = sequelize.define('Message', {
  name: {
    type: DataTypes.STRING,
    allowNull: false,
    validate: {
      notEmpty: true,
      len: [2, 50]
    }
  },
  email: {
    type: DataTypes.STRING,
    allowNull: false,
    validate: {
      isEmail: true
    }
  },
  subject: {
    type: DataTypes.STRING,
    allowNull: false,
    validate: {
      notEmpty: true,
      len: [2, 100]
    }
  },
  content: {
    type: DataTypes.TEXT,
    allowNull: false,
    validate: {
      notEmpty: true,
      len: [2, 2000]
    }
  },
  read: {
    type: DataTypes.BOOLEAN,
    allowNull: false,
    defaultValue: false
  }
});

module.exports = Message; 